home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / libx11.lha / libX11 / resources.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-22  |  7.5 KB  |  320 lines

  1. /* Copyright (c) 1996 by Terje Pedersen.  All Rights Reserved   */
  2. /*                                                              */
  3. /* By using this code you will agree to these terms:            */
  4. /*                                                              */
  5. /* 1. You may not use this code for profit in any way or form   */
  6. /*    unless an agreement with the author has been reached.     */
  7. /*                                                              */
  8. /* 2. The author is not responsible for any damages caused by   */
  9. /*    the use of this code.                                     */
  10. /*                                                              */
  11. /* 3. All modifications are to be released to the public.       */
  12. /*                                                              */
  13. /* Thats it! Have fun!                                          */
  14. /* TP                                                           */
  15. /*                                                              */
  16.  
  17. /***
  18.    NAME
  19.      resources
  20.    PURPOSE
  21.      resource handling.
  22.    NOTES
  23.      
  24.    HISTORY
  25.      Terje Pedersen - Mar 12, 1995: Created.
  26. ***/
  27.  
  28. #include <intuition/intuition.h>
  29. /*#include <intuition/intuitionbase.h>*/
  30. #include <clib/intuition_protos.h>
  31.  
  32. #include <graphics/gfx.h>
  33. #include <graphics/gfxbase.h>
  34. #include <graphics/gfxmacros.h>
  35. #include <graphics/displayinfo.h>
  36. #include <devices/timer.h>
  37.  
  38. #include <proto/intuition.h>
  39. #include <proto/graphics.h>
  40. #include <proto/gadtools.h>
  41. #include <proto/layers.h>
  42.  
  43. #include <dos.h>
  44. #include <signal.h>
  45. #include <stdlib.h>
  46. #include <time.h>
  47. #include <stdio.h>
  48.  
  49. #include "libX11.h"
  50.  
  51. #define XLIB_ILLEGAL_ACCESS 1
  52.  
  53. #include <X11/X.h>
  54. #include <X11/Xlib.h>
  55. #include <X11/Xutil.h>
  56. #include <X11/Intrinsic.h>
  57. #include <X11/IntrinsicP.h>
  58. #include <X11/CoreP.h>
  59.  
  60. #include "amigax_proto.h"
  61. #include "amiga_x.h"
  62.  
  63. #include "resource_list.h"
  64.  
  65. listnode *_Xresources=NULL;
  66.  
  67. String *_XtFallbackResource=NULL;
  68.  
  69. char *X11ResourceManagerString="AmigaResources";
  70. XrmDatabase X11DefaultResources=NULL;
  71.  
  72. extern listnode *makenode(char *,char *);
  73. extern int debugxemul;
  74.  
  75. char *XResourceManagerString(display)
  76.      Display *display;
  77. {/*  File 'xv.o' */
  78. #ifdef DEBUGXEMUL_ENTRY
  79.   printf("XResourceManagerString\n");
  80. #endif
  81.   return(X11ResourceManagerString);
  82. }
  83.  
  84. void XrmSetDatabase(display, database)
  85.      Display *display;
  86.      XrmDatabase database;
  87. {
  88. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  89.   printf("WARNING: XrmSetDatabase\n");
  90. #endif
  91. }
  92.  
  93. Bool XrmGetResource(database, str_name, str_class,
  94.             str_type_return, value_return)
  95.      XrmDatabase database;
  96.      _Xconst char *str_name;
  97.      _Xconst char *str_class;
  98.      char **str_type_return;
  99.      XrmValue *value_return;
  100. {/*          File 'resources.o'*/
  101.   char str[80];
  102.   char *lookfor,*entry,*c;
  103. #ifdef DEBUGXEMUL_ENTRY
  104.   printf("XrmGetResource\n");
  105. #endif
  106.   if(debugxemul)
  107.     printf("XrmGetResource name: [%s]\n",str_name);
  108.  
  109.   if(database!=NULL){
  110.     entry=findentry((listnode*)database,str_name);
  111.     if(entry){
  112.       value_return->size=strlen(entry);
  113.       value_return->addr=entry;
  114.       return(1);
  115.     }else{
  116.       value_return->size=0;
  117.       value_return->addr=NULL;
  118.     }
  119.   }
  120.  
  121.   if((c=strchr(str_name,'.'))!=NULL) strcpy(str,c);
  122.   else if((c=strchr(str_name,'*'))!=NULL) strcpy(str,c);
  123.   else if((c=strchr(str_name,'-'))!=NULL) strcpy(str,c);
  124.   else{
  125.     str[0]='.';
  126.     strcpy(&str[1],str_name);
  127.   }
  128.  
  129.   if(_XtFallbackResource){
  130.     char *hit;
  131.     int n=0;
  132.     while((entry=_XtFallbackResource[n++])){
  133.       if((hit=strstr(entry,str+1))!=NULL){
  134.     char *p=strchr(hit,':')+1;
  135.     while((*p==' '||*p==9)&&*p!=0)p++;
  136.     if(p){
  137.       value_return->size=strlen(p);
  138.       value_return->addr=p;
  139.       return(1);
  140.     }
  141.       }
  142.       
  143.     }
  144.   }
  145.  
  146.   return(0);
  147. }
  148.  
  149. XrmDatabase XrmGetStringDatabase(data)
  150.      char *data;
  151. {
  152. #ifdef DEBUGXEMUL_ENTRY
  153.   printf("XrmGetStringDatabase\n");
  154. #endif
  155.   return(X11DefaultResources);
  156. }
  157.  
  158. void XrmMergeDatabases(source_db, target_db)
  159.      XrmDatabase source_db, *target_db;
  160. {
  161. #ifdef DEBUGXEMUL_ENTRY
  162.   printf("XrmMergeDatabases\n");
  163. #endif
  164.   if(!(*target_db)) *target_db=source_db;
  165.   return(0);
  166. }
  167.  
  168. void X11ScanFile(FILE *fp){
  169.   while(!feof(fp)){
  170.     char str1[80],str2[40],*c;
  171.     fscanf(fp,"%s %s",str1,str2);
  172.     if( (c=strrchr(str1,':'))!=NULL) *c=0;
  173.     if(str1[0]!='!')
  174.       XrmPutStringResource((listnode**)&X11DefaultResources,str1,str2);
  175.     else while(fgetc(fp)!='\n'&&!feof(fp));
  176.   }
  177. }
  178.  
  179. void XrmInitialize(){/*           File 'xv.o' */
  180.   FILE *fp;
  181. #ifdef DEBUGXEMUL_ENTRY
  182.   printf("XrmInitialize\n");
  183. #endif
  184.   if(X11DefaultResources!=NULL) return;
  185.   makenull((listnode **)(&X11DefaultResources));
  186.   fp=fopen("AmigaDefaults","r");
  187.   if(!fp){
  188.     fp=fopen("libx11:AmigaDefaults","r");
  189.     if(!fp) return;
  190.   }
  191.   X11ScanFile(fp);
  192.   fclose(fp);
  193.   return(0);
  194. }
  195.  
  196. XrmDatabase XrmGetFileDatabase(filename)
  197.      char *filename;
  198. {/*      File 'xv.o' */
  199. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  200.   printf("WARNING: XrmGetFileDatabase\n");
  201. #endif
  202.   return(0);
  203. }
  204.  
  205. void XrmDestroyDatabase(database)
  206.      XrmDatabase database;
  207. {
  208. #ifdef DEBUGXEMUL_ENTRY
  209.   printf("XrmDestroyDatabase\n");
  210. #endif
  211.   deletelist(&database);
  212.   return(0);
  213. }
  214.  
  215. void XrmPutStringResource(database, specifier, value)
  216.       XrmDatabase *database;
  217.      char *specifier;
  218.      char *value;
  219. {/*    File 'main.o'*/
  220. #ifdef DEBUGXEMUL_ENTRY
  221.   printf("XrmPutStringResource\n");
  222. #endif
  223.   if(debugxemul) printf("XrmPutStringResource: specifier [%s] value [%s]\n",specifier,value);
  224.   if(*database==NULL){
  225.     makenull((listnode**)database);
  226.   }
  227.   insert((listnode**)database,makenode(specifier,value));
  228. }
  229.  
  230. void XrmPutResource(database, specifier, type, value)
  231.      XrmDatabase *database;
  232.      char *specifier;
  233.      char *type;
  234.      XrmValue *value;
  235. {/*          File 'main.o'*/
  236. #ifdef DEBUGXEMUL_ENTRY
  237.   if(debugxemul) printf("XrmPutResource: specifier [%s]\n");
  238. #endif
  239.   deleteentry(database,specifier);
  240.   insert(database,makenode(specifier,value->addr));
  241. }
  242.  
  243. XrmDatabase XtDatabase(display)
  244.      Display *display;
  245. {
  246. #ifdef DEBUGXEMUL_ENTRY
  247.   printf("XtDatabase\n");
  248. #endif
  249. /*  if(_Xresources==NULL) makenull(&_Xresources);
  250.   return(_Xresources);*/
  251.   if(X11DefaultResources==NULL){
  252.     makenull(&X11DefaultResources);
  253.   }
  254.   return(X11DefaultResources);
  255. }
  256.  
  257. void XrmPutLineResource(database, line)
  258.      XrmDatabase *database;
  259.      char *line;
  260. {/*      File 'xargs.o' */
  261. #ifdef DEBUGXEMUL_ENTRY
  262.   printf("XrmPutLineResource\n");
  263. #endif
  264.   if(!(*database)) *database=XtDatabase(NULL);
  265.   return(0);
  266. }
  267.  
  268. void XrmParseCommand(database, table, table_count, name, argc_in_out,argv_in_out)
  269.      XrmDatabase *database;
  270.      XrmOptionDescList table;
  271.      int table_count;
  272.      char *name;
  273.      int *argc_in_out;
  274.      char **argv_in_out;
  275. {/*         File 'xargs.o' */
  276. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  277.   printf("WARNING: XrmParseCommand\n");
  278. #endif
  279.   return(0);
  280. }
  281.  
  282. listnode *X11InternalAtoms=NULL;
  283.  
  284. #define INTERNALATOMS
  285.  
  286. Atom XInternAtom(display, property_name, only_if_exists)
  287.      Display *display;
  288.      char *property_name;
  289.      Bool only_if_exists;
  290. {/*             File 'xdaliclock.o'*/
  291. #ifdef DEBUGXEMUL_ENTRY
  292.   printf("XInternAtom\n");
  293. #endif
  294. #ifdef INTERNALATOMS
  295.   if(only_if_exists){
  296.     return((Atom)findentry(X11InternalAtoms,property_name));
  297.   } else {
  298.     if(findentry(X11InternalAtoms,property_name)==NULL)
  299.       insert(&X11InternalAtoms,makenode(property_name,property_name));
  300.     return((Atom)findentry(X11InternalAtoms,property_name));
  301.   }
  302. #else
  303.   return 0;
  304. #endif
  305. }
  306.  
  307. void X11exit_resources(void){
  308. #ifdef INTERNALATOMS
  309.   if(X11InternalAtoms) deletelist(&X11InternalAtoms);
  310. #endif
  311.   deletelist(&X11DefaultResources);
  312. }
  313.  
  314. void X11init_resources(void){
  315. #ifdef INTERNALATOMS
  316.   makenull(&X11InternalAtoms);
  317. #endif
  318.   XrmInitialize();
  319. }
  320.